package com.hetao.xx.service;

import android.content.Context;

import com.hetao.xx.Global;
import com.hetao.xx.constants;
import com.hetao.xx.game.common.EventEnum;
import com.hetao.xx.game.common.GoodEnum;
import com.hetao.xx.game.model.NpcEvent;
import com.hetao.xx.game.model.Place;
import com.hetao.xx.game.model.User;
import com.hetao.xx.game.model.UserArms;
import com.hetao.xx.orm.GoodsVo;
import com.hetao.xx.orm.NpcEventVo;
import com.hetao.xx.orm.NpcVo;
import com.hetao.xx.orm.PlaceNpcVo;
import com.hetao.xx.orm.PlaceVo;
import com.hetao.xx.orm.UserVo;

public class MakeWorldService {

    public void makeGoods() {
        Global.getInstant().goodsDao.dropTable();
        Global.getInstant().npcDao.dropTable();
        Global.getInstant().npcEventDao.dropTable();
        Global.getInstant().placeDao.dropTable();
        Global.getInstant().placeNpcDao.dropTable();


        makeFood("草药", 50, 10);
        makeHangcheng();

    }

    /**
     * 生成杭城环境
     */
    public void makeHangcheng() {

        PlaceVo parentPlace = makePlace("杭城", "一座美丽的城市\n不要上山，山上哟老虎。");

        makePlace("客栈", "休息一天，精神倍爽!\n进度保存", parentPlace.id);

        NpcVo npcVo = makeNpc("翠花", parentPlace.id);
        makeNpcEvent(npcVo.id, EventEnum.Talk, "客观，休息一天，1两银子");
        makePlaceNpc(npcVo.id, parentPlace.id);

        makePlace("武馆", "强身健体，保家卫国。", parentPlace.id);
        makePlace("城外小路", "城外很危险，小心脚下遇险。", parentPlace.id);
        NpcVo tiger = makeNpc("小小老虎", parentPlace.id);
        makePlaceNpc(tiger.id, parentPlace.id);
        makeNpcEvent(tiger.id, EventEnum.Fight, "来呀，互相伤害呀");


    }

    private PlaceVo makePlace(String name, String message) {
        return makePlace(name, message, 0);
    }

    private PlaceVo makePlace(String name, String message, int prePlaceId) {
        PlaceVo place = new PlaceVo();
        place.name = name;
        place.message = message;
        place.prePlaceId = prePlaceId;
        Global.getInstant().placeDao.add(place);
        return place;
    }

    public static NpcVo makeNpc(String name, int placeId) {
        NpcVo bean = new NpcVo();
        bean.setName(name);
        bean.setHp(constants.oriHp);
        bean.setMp(constants.oriMp);
        bean.setAttack(constants.oriAttack);
        bean.setDefence(constants.oriDefence);
        bean.setSpeed(constants.oriSpeed);
        bean.setPlaceId(placeId);
        Global.getInstant().npcDao.add(bean);
        return bean;
    }

    public static PlaceNpcVo makePlaceNpc(int npcId, int placeId){
        return makePlaceNpc(npcId,placeId, 100);
    }

    public static PlaceNpcVo makePlaceNpc(int npcId, int placeId, int present) {
        PlaceNpcVo bean = new PlaceNpcVo();
        bean.NpcId = npcId;
        bean.placeId = placeId;
        bean.present = present;
        Global.getInstant().placeNpcDao.add(bean);
        return bean;
    }

    public static NpcEventVo makeNpcEvent(int npcId, EventEnum event, String message) {
        return makeNpcEvent(npcId, event, message, EventEnum.Back);
    }
    public static NpcEventVo makeNpcEvent(int npcId, EventEnum event, String message, EventEnum ok) {
        return makeNpcEvent(npcId, event, message, ok, EventEnum.Back);
    }
    public static NpcEventVo makeNpcEvent(int npcId, EventEnum event, String message, EventEnum ok, EventEnum cancel) {
        NpcEventVo bean = new NpcEventVo();
        bean.eventType = event;
        bean.message = message;
        bean.okEvent = ok;
        bean.cancelEvent = cancel;
        bean.npcId = npcId;
        Global.getInstant().npcEventDao.add(bean);
        return bean;
    }

    public GoodsVo makeFood(String name, int hp, int mp) {
        GoodsVo vo = new GoodsVo();
        vo.name = name;
        vo.type = GoodEnum.food;
        vo.hp = hp;
        vo.mp = mp;
        Global.getInstant().goodsDao.add(vo);
        return vo;
    }


    public User makeUserRole(String name) {
        UserVo aUser = new UserVo();
        aUser.setName(name);
        aUser.setHp(constants.oriHp);
        aUser.setMp(constants.oriMp);
        aUser.setAttack(constants.oriAttack);
        aUser.setDefence(constants.oriDefence);
        aUser.setSpeed(constants.oriSpeed);
        aUser.setPlaceId(1);
        aUser.isExercise = false;
        aUser.experience = 10000;
        aUser.holeLevel = 0;
        aUser.money = 100000000;
        aUser.userLevel = 1;

        User user = new User();
        user.info = aUser;
        user.amrs = new UserArms();
        return user;
    }


}
